package com.koron.common.core.business.workflow.feign;

import com.koron.bean.base.Response;
import com.koron.bean.workflow.RedirectQuery;
import com.koron.bean.workflow.SubmitterParam;
import com.koron.bean.workflow.WorkflowUser;
import com.koron.common.core.feignConfig.FeignConfig;
import feign.Feign;
import feign.Target;
import feign.codec.Decoder;
import feign.codec.Encoder;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.FeignClientsConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import java.net.URI;
import java.util.List;

/**
 * @author jzp
 * @since 2022/1/17
 */
@Slf4j
@Component
@Import(FeignClientsConfiguration.class)
public class CallerService {
    private final CallerFeignService callerFeignService;

    @Autowired
    public CallerService(Decoder decoder, Encoder encoder, FeignConfig feignConfig) {
        callerFeignService = Feign.builder()
                .encoder(encoder)
                .decoder(decoder)
                .requestInterceptor(feignConfig)
                .target(Target.EmptyTarget.create(CallerFeignService.class));
    }

    @SneakyThrows
    public Response<Object> updateStatus(String url, RedirectQuery redirectQuery) {
        return callerFeignService.updateStatus(new URI(url), redirectQuery);
    }

    @SneakyThrows
    public Response<List<WorkflowUser>> listWorkflowUser(String url, SubmitterParam submitterParam) {
        return callerFeignService.listWorkflowUser(new URI(url), submitterParam);
    }

}
